{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d2ce6888-21f8-4047-9dbe-433ec7e4b034",
   "metadata": {},
   "source": [
    "# Grouped Bar Chart\n",
    "\n",
    "A grouped bar chart that compares values across multiple categories and subgroups. This example uses the penguins dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e5ed01c-1f29-4bf9-a0d3-d767ab8fc177",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.penguins('pandas')\n",
    "grouped = df.groupby(['species', 'sex'], observed=True)['flipper_length_mm'].mean()\n",
    "\n",
    "grouped.hvplot.bar(\n",
    "    x='species',\n",
    "    y='flipper_length_mm',\n",
    "    by='sex',\n",
    "    title='Grouped Bar Chart (Bokeh)',\n",
    "    xlabel='Species',\n",
    "    ylabel='Avg. Flipper Length (mm)',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7178a426-2886-42dc-b769-3255c5ed7da6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "hvplot.extension('matplotlib')\n",
    "\n",
    "df = hvplot.sampledata.penguins('pandas')\n",
    "grouped = df.groupby(['species', 'sex'], observed=True)['flipper_length_mm'].mean()\n",
    "\n",
    "grouped.hvplot.bar(\n",
    "    x='species',\n",
    "    y='flipper_length_mm',\n",
    "    by='sex',\n",
    "    title='Grouped Bar Chart (Matplotlib)',\n",
    "    xlabel='Species',\n",
    "    ylabel='Avg Flipper Length (mm)',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b61fa89b-ac33-42d2-bf5f-3ed9541c1e3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fa60024-a145-4ff1-92e5-01eb6d270240",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [Bar Plots reference documentation](../../ref/api/manual/hvplot.hvPlot.bar.ipynb).\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
